package com.cloud.system.controller;

import com.cloud.common.domain.Result;
import com.cloud.controller.BaseController;
import com.cloud.entity.SysDeptArea;
import com.cloud.security.aop.RequestPermissions;
import com.cloud.user_info.service.ISysDeptAreaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 地区管理
 *
 * @author yzj
 * @since 2022-11-21
 */
@Tag(name = "区域负责人")
@RestController
@RequestMapping("/system/deptArea")
public class SysDeptAreaController extends BaseController {

    @Autowired
    private ISysDeptAreaService sysDeptAreaService;

    @Operation(summary = "地区负责人分页")
    @RequestPermissions("system:deptArea:list")
    @GetMapping("/list")
    public Result list(SysDeptArea deptArea) {
        startPage();
        List<SysDeptArea> list = sysDeptAreaService.selectSysDeptAreaList(deptArea);
        return getDataTable(list);
    }

    @Operation(summary = "查询地区负责人详情")
    @RequestPermissions("system:deptArea:query")
    @GetMapping("/getInfo")
    public Result getInfo(Long id) {
        return Result.success("查询成功", sysDeptAreaService.selectDeptAreaInfo(id));
    }

    @Operation(summary = "查询所有地区负责人列表")
    @GetMapping("allList")
    public Result getInDeptAreaList(SysDeptArea deptArea) {
        List<SysDeptArea> list = sysDeptAreaService.selectSysDeptAreaList(deptArea);
        return Result.success("查询成功", list);
    }

    @Operation(summary = "Feign内部调用（根据地区编号查询地区）")
    @RequestMapping(value = "/inAuth/getInDeptAreaByCode", method = {RequestMethod.POST, RequestMethod.GET})
    public Result getInDeptAreaByCode(String areaCode) {
        return Result.success("查询成功", sysDeptAreaService.selectDeptAreaByCode(areaCode));
    }

    @Operation(summary = "Feign内部调用(根据主键查询地区)")
    @RequestMapping(value = "/inAuth/selectAreaById", method = {RequestMethod.POST, RequestMethod.GET})
    public Result selectAreaById(Long areaId) {
        return Result.success("查询成功", sysDeptAreaService.selectAreaById(areaId));
    }

    @Operation(summary = "Feign内部调用(根据区域名称查询区域信息)")
    @RequestMapping(value = "/inAuth/getInAreaByName", method = {RequestMethod.POST, RequestMethod.GET})
    public Result getInAreaByName(String areaName) {
        return Result.success("查询成功", sysDeptAreaService.selectAreaByName(areaName));
    }

    @Operation(summary = "查询树状区域列表")
    @GetMapping("/treeSelect")
    public Result treeSelect(SysDeptArea deptArea) {
        return Result.success("查询成功", sysDeptAreaService.buildAreaTree(deptArea));
    }

}
